package priv.pront.code.national.acwing.dp.linear;

import java.util.Scanner;

public class A902_最短编辑距离 {

    static int n,m;
    static String s, t;
    static int [][] dp;

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        s = scanner.next();
        m = scanner.nextInt();
        t = scanner.next();
        dp = new int[n + 1][m + 1];
        for(int i = 1; i <= n; i++){
            dp[i][0] = i;
        }
        for(int i = 1; i <= m; i++){
            dp[0][i] = i;
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <=m; j++){
                dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - 1]) + 1;
                dp[i][j] = Math.min(dp[i][j], dp[i - 1][j - 1] + (s.charAt(i - 1) == t.charAt(j - 1) ? 0 : 1));
            }
        }

        System.out.println(dp[n][m]);
    }
}
